gusucode.com > 耐品图片管理系统 标准版A > 耐品图片管理系统 标准版A/Inc/clsEmail.asp

    <%
'-----------------------------------------------------------------------
'--- EMAIL邮件处理类模块
'--- Copyright (c) 2006 www.naipin.com, Inc.
'--- Script Written By lyout
'--- 2006-05-19
'-----------------------------------------------------------------------
'--- 设置项
'-----------------------------------------------------------------------
'--- SmtpServer		设置SMTP邮件服务器地址
'--- FromEmail		设置发件人的E-MAIL地址
'--- FromName		设置发送人名称
'--- ContentType	设置邮件类型 默认:text/html
'--- Charset		设置编码类型 默认:gb2312
'--- SendObject		设置选取组件 1=Jmail,2=Cdonts
'-----------------------------------------------------------------------
'--- 属性
'-----------------------------------------------------------------------
'--- SendMail Email, Topic, MailBody	收件人地址,标题,邮件内容
'-----------------------------------------------------------------------
'--- 获取信息
'-----------------------------------------------------------------------
'--- ErrCode			信息编号 0=正常
'--- Description		相应操作信息
'--- Count				发送邮件数
'-----------------------------------------------------------------------
Class Lyout_Mail
	Public Count,ErrCode,ErrMsg
	Public UserName,Password,FromEmail,FromName
	Public SmtpServer,ContentType,Charset
	Private Obj,cdoConfig,Object

	Private Sub Class_Initialize()
		Object = 0
		Count = 0
		ErrCode = 0
		ContentType = "text/html"
		Charset = "gb2312"
	End Sub

	Private Sub Class_Terminate()
		If Isobject(Obj) Then
			Set Obj = Nothing
		End If
		If IsObject(cdoConfig) Then
			Set cdoConfig = Nothing
		End If
	End Sub
	'获取错误信息
	Public Property Get Description()
		Description = ErrMsg
	End Property
	'设置选取组件 SendObject 0=Jmail,1=Cdonts,2=Aspemail
	Public Property Let SendObject(Byval Value)
		Object = Value
		On Error Resume Next
		Select Case Object
			Case 1
				Set Obj = Server.CreateObject("JMail.Message")
			Case 2
				Set Obj = Server.CreateObject("CDONTS.NewMail")
			Case Else
				ErrNumber = 2
		End Select
		If Err<>0 Then
			ErrNumber = 3
		End If
	End Property

	Private Property Let ErrNumber(Byval Value)
		ErrCode = Value
		ErrMsg = ErrMsg & Msg
	End Property
	Private Function Msg()
		Dim MsgValue
		Select Case ErrCode
		Case 1
			MsgValue = "未选取邮件组件或服务器不支持该组件!"
		Case 2
			MsgValue = "所选的组件不存在!"
		Case 3
			MsgValue = "错误:服务器不支持该组件!"
		Case 4
			MsgValue = "发送失败!"
		Case Else
			MsgValue = "正常。"
		End Select
		Msg = MsgValue
	End Function

	Public Sub SendMail(Byval Email,Byval Topic,Byval MailBody)
		If ErrCode <> 0 Then
			Exit Sub
		End If
		If Email="" or ISNull(Email) Then Exit Sub
		If Object>0 Then
			Select Case Object
				Case 1
					Jmail Email,Topic,MailBody
				Case 2
					Cdonts Email,Topic,Mailbody
				Case Else
					ErrNumber = 2
			End Select
		Else
			ErrNumber = 1
		End If
	End Sub

	Private Sub Jmail(Email,Topic,Mailbody)
		On Error Resume Next
		Obj.Silent = True
		Obj.Logging = True
		Obj.Charset = Charset
		If Not(UserName = "" Or Password = "") Then
			Obj.MailServerUserName = UserName '您的邮件服务器登录名
			Obj.MailServerPassword = Password '登录密码
		End If
		Obj.ContentType = ContentType
		Obj.Priority = 1
		Obj.From = FromEmail
		Obj.FromName = FromName
		Obj.AddRecipient Email
		Obj.Subject = Topic
		Obj.Body = Mailbody
		If Err<>0 Then
			ErrMsg = ErrMsg & "发送失败!原因:" & Err.Description
			ErrNumber = 4
		Else
			If Obj.Send (SmtpServer) Then
				Obj.ClearRecipients()
				If Err<>0 Then
					ErrMsg = ErrMsg & "发送失败!原因:" & Err.Description
					ErrNumber = 4
				Else
					Count = Count + 1
					ErrMsg = ErrMsg & "发送成功!"
				End If
			Else
				ErrMsg = ErrMsg & "发送失败!原因:"&Obj.Log
				ErrNumber = 4
			End If
		End If
	End Sub
		
	Private Sub Cdonts(Email,Topic,Mailbody)
		On Error Resume Next
		Obj.From = FromEmail
		Obj.To = Email
		Obj.Subject = Topic
		Obj.BodyFormat = 0 
		Obj.MailFormat = 0 
		Obj.Body = Mailbody
		If Err<>0 Then
			ErrMsg = ErrMsg & "发送失败!原因:" & Err.Description
			ErrNumber = 4
		Else
			Obj.Send
			If Err<>0 Then
				ErrMsg = ErrMsg & "发送失败!原因:" & Err.Description
				ErrNumber = 4
			Else
				Count = Count + 1
				ErrMsg = ErrMsg & "发送成功!"
			End If
		End If
	End Sub
End Class
%>